package com.zhtx.debt.customer.controller;

import com.zhtx.debt.customer.service.CustomerService;
import com.zhtx.debt.customer.vo.CustomerResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @description: 个债客户历史数据抽取到企债
 * @author: liujin
 * @create: 2020-05-07 10:26
 */
@Slf4j
@Controller
public class CustomerController {

    private ReentrantLock lock = new ReentrantLock();

    @Resource
    private CustomerService customerService;

    @PostMapping("/convey")
    @ResponseBody
    public CustomerResult convey() {
        CustomerResult result = new CustomerResult();
        if (lock.tryLock()) {
            try {
                customerService.convert();
                log.info("导入成功");
                result.setMsg("导入成功");
            } catch (Exception e) {
                log.error(e.getMessage(), e);
                result.setSuccess(false);
                result.setMsg(e.getMessage());
            } finally {
                lock.unlock();
            }
        } else {
            result.setSuccess(true);
            result.setMsg("数据正在导入中...");
        }

        return result;
    }


}
